package primetest.dto;

import java.sql.Date;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;

import primetest.utils.PasswordHash;

public class DoctorDto {
	private int seq;
	private String id;
	private String password;
	private String name;
	private int gender;
	private DepartmentDto departmentDto;
	private String degree;
	private String university;
	private int workType;
	private String workDomain;
	private String introduction;
	private Date birthDate;
	private Date joinHospitalDate;
	private String birthDateStr = "1111-11-11";
	private String joinHospitalDateStr = "1111-11-11";
	private String planePassword;
	private List<RoleDto> roleList;
	private boolean online;
	private List<PatientDto> patientList;
	private Queue<PatientDto> patientQueue;

	private boolean changePassword = false;

	// You must declared default constructor for Framework.
	public DoctorDto() {
		super();
		roleList = new ArrayList<RoleDto>();
		setOnline(true);
	}

	public DoctorDto(int seq, String id, String password, String name,
			int gender, DepartmentDto departmentDto, String degree,
			String university, int workType, String workDomain,
			String introduction, Date birthDate, Date joinHospitalDate,
			List<RoleDto> roleList) {
		this.seq = seq;
		this.id = id;
		this.password = password;
		this.name = name;
		this.gender = gender;
		this.departmentDto = departmentDto;
		this.degree = degree;
		this.university = university;
		this.workType = workType;
		this.workDomain = workDomain;
		this.introduction = introduction;
		this.birthDate = birthDate;
		this.joinHospitalDate = joinHospitalDate;
		this.roleList = roleList;
		this.planePassword = "";
		this.birthDateStr = birthDate.toString();
		this.joinHospitalDateStr = joinHospitalDate.toString();
		setOnline(true);
		this.setPatientList(new ArrayList<PatientDto>());
		this.setPatientQueue(new LinkedList<PatientDto>());
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;

	}

	public List<RoleDto> getRoleList() {
		return roleList;
	}

	public int getSeq() {
		return seq;
	}

	public void setSeq(int seq) {
		this.seq = seq;
	}

	public int getGender() {
		return gender;
	}

	public void setGender(int gender) {
		this.gender = gender;
	}

	public DepartmentDto getDepartmentDto() {
		return departmentDto;
	}

	public void setDepartmentDto(DepartmentDto departmentDto) {
		this.departmentDto = departmentDto;
	}

	public String getDegree() {
		return degree;
	}

	public void setDegree(String degree) {
		this.degree = degree;
	}

	public String getUniversity() {
		return university;
	}

	public void setUniversity(String university) {
		this.university = university;
	}

	public int getWorkType() {
		return workType;
	}

	public void setWorkType(int workType) {
		this.workType = workType;
	}

	public String getWorkDomain() {
		return workDomain;
	}

	public void setWorkDomain(String workDomain) {
		this.workDomain = workDomain;
	}

	public String getIntroduction() {
		return introduction;
	}

	public void setIntroduction(String introduction) {
		this.introduction = introduction;
	}

	public Date getBirthDate() {
		return birthDate;
	}

	public void setBirthDate(Date birthDate) {
		this.birthDate = birthDate;
	}

	public Date getJoinHospitalDate() {
		return joinHospitalDate;
	}

	public void setJoinHospitalDate(Date joinHospitalDate) {
		this.joinHospitalDate = joinHospitalDate;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getPlanePassword() {
		return planePassword;
	}

	public void setPlanePassword(String planePassword) {
		if (planePassword != null && !planePassword.equals("")) {
			changePassword = true;
			password = PasswordHash.makePasswordHash(planePassword);
		}
		this.planePassword = planePassword;
	}

	public boolean isChangePassword() {
		return changePassword;
	}

	public void saveDate() {
		try {
			birthDate = Date.valueOf(birthDateStr);
			joinHospitalDate = Date.valueOf(joinHospitalDateStr);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public void setAll(DoctorDto dot) {
		this.seq = dot.seq;
		this.id = dot.id;
		this.password = dot.password;
		this.name = dot.name;
		this.gender = dot.gender;
		this.departmentDto = dot.departmentDto;
		this.degree = dot.degree;
		this.university = dot.university;
		this.workType = dot.workType;
		this.workDomain = dot.workDomain;
		this.introduction = dot.introduction;
		this.birthDate = dot.birthDate;
		this.joinHospitalDate = dot.joinHospitalDate;
		this.roleList = dot.roleList;
		this.planePassword = dot.planePassword;
		this.birthDateStr = dot.birthDate.toString();
		this.joinHospitalDateStr = dot.joinHospitalDate.toString();

	}

	public boolean isValid() {
		if (name.length() == 0  || introduction.length() == 0) {
			return false;
		}
		return true;
	}

	public String getBirthDateStr() {
		return birthDateStr;
	}

	public void setBirthDateStr(String birthDateStr1) {
		this.birthDateStr = birthDateStr1;
	}

	public String getJoinHospitalDateStr() {
		return joinHospitalDateStr;
	}

	public void setJoinHospitalDateStr(String joinHospitalDateStr1) {
		this.joinHospitalDateStr = joinHospitalDateStr1;
	}

	public String getGenderName() {
		if (gender == 1) {
			return "Male";
		} else {
			return "Female";
		}
	}

	public int getDepartmentDtoSeq() {
		if (departmentDto != null) {
			return departmentDto.getSeq();
		} else {
			return -1;
		}
	}



	public String getDepartmentName() {
		if (departmentDto != null) {
			return departmentDto.getName();
		} else {
			return "";
		}
	}

	public boolean isOnline() {
		return online;
	}

	public void setOnline(boolean online) {
		this.online = online;
	}

	public List<PatientDto> getPatientList() {
		return patientList;
	}

	public void setPatientList(List<PatientDto> patientList) {
		this.patientList = patientList;
	}

	public Queue<PatientDto> getPatientQueue() {
		return patientQueue;
	}

	public void setPatientQueue(Queue<PatientDto> patientQueue) {
		this.patientQueue = patientQueue;
	}

	public int getQueueSize() {
		return patientQueue.size();

	}

	public String getCurrentPatientName() {
		PatientDto patient = patientQueue.peek();
		if (patient != null) {
			return patient.getName();
		}
		return null;
	}
}
